Skip to content

Allow section override when using patchable-function-entries#157445

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
pmur:murp/extend-patchable
Jun 30, 2026
Merged

Allow section override when using patchable-function-entries#157445
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
pmur:murp/extend-patchable

Conversation

@pmur

@pmur pmur commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

View all comments

Sometimes it is necessary to group patchable function entrypoint records in distinct linker sections. This is the case for some bpf functions within the linux kernel which shouldn't be visible to ftrace.

Extend -Zpatchable-function-entry to accept an argument of the form prefix_nops,total_nops,record_section, which places all entry record into a user specified section.

Likewise, extend the patchable_function_entry attribute to accept an optional section="name" option to place a function into a specific section.

This is made possible by llvm attribute patchable-function-entry-section added in llvm 21.

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 4, 2026
@pmur pmur marked this pull request as ready for review June 4, 2026 21:52
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 4, 2026
@rustbot

rustbot commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 4, 2026
@rustbot

rustbot commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 19 candidates

@pmur

pmur commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

I think this is an important feature which we weren't aware of during the initial implementation of #123115.

Adding this should allow Rust to reduce the need to implement mcount or fentry (essentially x86 only) for compatibility within the linux kernel, and likely reduces the need for rust-lang/rfcs#3917.

@pmur

pmur commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot reroll

@rustbot rustbot assigned chenyukang and unassigned jackh726 Jun 17, 2026
@chenyukang

Copy link
Copy Markdown
Member

@rustbot reroll

@rustbot rustbot assigned mejrs and unassigned chenyukang Jun 22, 2026

@mejrs mejrs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the rules for valid section names? This implementation accepts every string. Is #[patchable_function_entry(section = "")] valid? Can I use names with null bytes in them?

View changes since this review

Comment thread compiler/rustc_session/src/config.rs
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 24, 2026
@rustbot

rustbot commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

sym::section => {
// Duplicate entries are not allowed
if section.is_some() {
errored = true;

@mejrs mejrs Jun 24, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: usually we use Option<ErrorGuaranteed> for "has errored" variables. Feel free to implement it or not, at your option.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can that be done within the attribute parsing framework? I think I am constrained to the SingleAttributeParser trait.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions like duplicate_key return ErrorGuaranteed for this reason.

@pmur

pmur commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

What are the rules for valid section names?

I think that gets punted to the assembler, and the targets object file format. For ELF, I think that is any nul terminated string.

@rust-bors

This comment has been minimized.

@mejrs

mejrs commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

What are the rules for valid section names?

I think that gets punted to the assembler, and the targets object file format. For ELF, I think that is any nul terminated string.

So this would fail at the codegen stage? It makes for a better user experience to reject it earlier, similar to #155817

@pmur pmur force-pushed the murp/extend-patchable branch from 8f7613b to c729ed3 Compare June 25, 2026 15:57
@rustbot

This comment has been minimized.

@pmur

pmur commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Updated to handle nul's more gracefully. llvm doesn't handle the inline nul gracefully.

@pmur pmur force-pushed the murp/extend-patchable branch from c729ed3 to 55b62aa Compare June 25, 2026 21:16
@pmur pmur force-pushed the murp/extend-patchable branch from a81de40 to c340e8a Compare June 29, 2026 14:53
@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@mejrs mejrs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors

rust-bors Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

📌 Commit c340e8a has been approved by mejrs

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 29, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 29, 2026
Allow section override when using patchable-function-entries

Sometimes it is necessary to group patchable function entrypoint records in distinct linker sections. This is the case for some bpf functions within the linux kernel which shouldn't be visible to ftrace.

Extend `-Zpatchable-function-entry` to accept an argument of the form `prefix_nops,total_nops,record_section`, which places all entry record into a user specified section.

Likewise, extend the `patchable_function_entry` attribute to accept an optional `section="name"` option to place a function into a specific section.

This is made possible by llvm attribute `patchable-function-entry-section` added in llvm 21.
rust-bors Bot pushed a commit that referenced this pull request Jun 29, 2026
Rollup of 12 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158169 (Fix debuginfo compression in bootstrap)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158417 (Avoid ICE when cfg_eval recovers no item from derive input)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
Allow section override when using patchable-function-entries

Sometimes it is necessary to group patchable function entrypoint records in distinct linker sections. This is the case for some bpf functions within the linux kernel which shouldn't be visible to ftrace.

Extend `-Zpatchable-function-entry` to accept an argument of the form `prefix_nops,total_nops,record_section`, which places all entry record into a user specified section.

Likewise, extend the `patchable_function_entry` attribute to accept an optional `section="name"` option to place a function into a specific section.

This is made possible by llvm attribute `patchable-function-entry-section` added in llvm 21.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
Allow section override when using patchable-function-entries

Sometimes it is necessary to group patchable function entrypoint records in distinct linker sections. This is the case for some bpf functions within the linux kernel which shouldn't be visible to ftrace.

Extend `-Zpatchable-function-entry` to accept an argument of the form `prefix_nops,total_nops,record_section`, which places all entry record into a user specified section.

Likewise, extend the `patchable_function_entry` attribute to accept an optional `section="name"` option to place a function into a specific section.

This is made possible by llvm attribute `patchable-function-entry-section` added in llvm 21.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 29, 2026
Allow section override when using patchable-function-entries

Sometimes it is necessary to group patchable function entrypoint records in distinct linker sections. This is the case for some bpf functions within the linux kernel which shouldn't be visible to ftrace.

Extend `-Zpatchable-function-entry` to accept an argument of the form `prefix_nops,total_nops,record_section`, which places all entry record into a user specified section.

Likewise, extend the `patchable_function_entry` attribute to accept an optional `section="name"` option to place a function into a specific section.

This is made possible by llvm attribute `patchable-function-entry-section` added in llvm 21.
rust-bors Bot pushed a commit that referenced this pull request Jun 29, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #155722 (Introduce aarch64-unknown-linux-pauthtest target)
 - #156230 (tests: check wasm compiler_builtins object architecture)
 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158169 (Fix debuginfo compression in bootstrap)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
 - #158564 (fix `-Z min-recursion-limit` unstable chapter name)
 - #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
 - #158582 (Comment on needed RAM in huge-stacks.rs)
rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #155722 (Introduce aarch64-unknown-linux-pauthtest target)
 - #156230 (tests: check wasm compiler_builtins object architecture)
 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158169 (Fix debuginfo compression in bootstrap)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`)
 - #158556 (delegation: store child segment flag in `PathSegment`)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158081 (trait-system: Recover deferred closure calls after errors)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158468 (Include default-stability info in rustdoc JSON.)
 - #158564 (fix `-Z min-recursion-limit` unstable chapter name)
 - #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+)
 - #158582 (Comment on needed RAM in huge-stacks.rs)
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors try jobs=dist-x86_64-msvc

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
Allow section override when using patchable-function-entries


try-job: dist-x86_64-msvc
rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158591 (Fix spacing issue for unused parentheses lint)
rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158591 (Fix spacing issue for unused parentheses lint)
@rust-bors

rust-bors Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: b51b1b6 (b51b1b640424281574727bc510e87d381ef1e3e5)
Base parent: 0966944 (096694416a41840709140eb0fd0ca193d1a3e6ba)

rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158591 (Fix spacing issue for unused parentheses lint)
rust-bors Bot pushed a commit that referenced this pull request Jun 30, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - #158256 (Avoid parser panics bubbling out to proc macros)
 - #158561 (Avoid building rustdoc for tests without doctests)
 - #158562 (Improve tracing of steps in bootstrap)
 - #157445 (Allow section override when using patchable-function-entries)
 - #158327 (Move attribute and keyword docs from `std` to `core`)
 - #158591 (Fix spacing issue for unused parentheses lint)
@rust-bors rust-bors Bot merged commit 86eb76f into rust-lang:main Jun 30, 2026
14 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 30, 2026
rust-timer added a commit that referenced this pull request Jun 30, 2026
Rollup merge of #157445 - pmur:murp/extend-patchable, r=mejrs

Allow section override when using patchable-function-entries

Sometimes it is necessary to group patchable function entrypoint records in distinct linker sections. This is the case for some bpf functions within the linux kernel which shouldn't be visible to ftrace.

Extend `-Zpatchable-function-entry` to accept an argument of the form `prefix_nops,total_nops,record_section`, which places all entry record into a user specified section.

Likewise, extend the `patchable_function_entry` attribute to accept an optional `section="name"` option to place a function into a specific section.

This is made possible by llvm attribute `patchable-function-entry-section` added in llvm 21.
bjorn3 pushed a commit to bjorn3/miri that referenced this pull request Jul 1, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#158073 (bootstrap: fix panic when repo path contains spaces by switching to CARGO_ENCODED_RUSTFLAGS)
 - rust-lang/rust#158256 (Avoid parser panics bubbling out to proc macros)
 - rust-lang/rust#158561 (Avoid building rustdoc for tests without doctests)
 - rust-lang/rust#158562 (Improve tracing of steps in bootstrap)
 - rust-lang/rust#157445 (Allow section override when using patchable-function-entries)
 - rust-lang/rust#158327 (Move attribute and keyword docs from `std` to `core`)
 - rust-lang/rust#158591 (Fix spacing issue for unused parentheses lint)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants